package server.utils;

import java.util.List;
import java.util.Map;

import server.ServerEngin;
import server.jdbc.DAOUtil;
import server.jdbc.JDBCException;

import com.core.async.AsyncObject;

/**
 * 抽象的异步查询数据库
 * @author King
 *
 */
public abstract class AbsAsyncQueryDb extends AsyncObject
{
	
	public AbsAsyncQueryDb(String sql,List params)
	{
//		ServerEngin.getInstance().getAsyncService().addAsyncBackWork(this, "query", sql,params);
		//ServerEngin.getInstance().getAsyncService()
		//AsyncQueryExample.asyncService
	}
	
	/**查询结果  不可能为null  没有结果时size为0**/
	protected List<Map<String, Object>> result;
	
	/**
	 * 异步查询
	 * @param params
	 * @throws JDBCException 
	 */
	public void query(String sql,List params) throws JDBCException 
	{
		DAOUtil dao = DAOUtil.getInstance();
		result = dao.query(sql, params);
	}
	
	@Override
	public void doCallBack() throws Exception
	{
		queryBack();
	}
	
	/**
	 * 查询完后处理
	 */
	protected abstract void queryBack();

}
